Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read More block: add aria-label and screen reader text #45490

Merged
merged 6 commits into from
Nov 10, 2022

Conversation

jffng
Copy link
Contributor

@jffng jffng commented Nov 2, 2022

What?

This PR adds an aria-label and .screen-reader-text to the output of the Read More block. I could use some input as to whether the resulting markup is acceptable.

Why?

Fixes 1/2 of #45396

Links must avoid repetitive non-contextual text strings such as ‘read more…’ and must make sense if taken out of context. Bare urls must not be used as links. Supporting text may use a screen reader class to hide text visually.

https://make.wordpress.org/themes/handbook/review/accessibility/required/#repetitive-link-text

How?

See above.

Testing Instructions

  1. Check out this PR and add the following block markup for a Query to a post or template:
<!-- wp:query {"queryId":0,"query":{"perPage":3,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:post-title /-->
<!-- wp:post-featured-image /-->
<!-- wp:read-more /-->
<!-- /wp:post-template -->
<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->
<!-- wp:query-pagination-numbers /-->
<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination --></div>
<!-- /wp:query -->
  1. Ensure the resulting markup for the Read More link is accessible. Here is an example:
<a class="wp-block-read-more" href="http://gutenbergtest.local/341-2/" target="_self" aria-label="Post ID: 341">Continue Reading<span class="screen-reader-text">This is my post title</span></a>

Screenshots or screencast

@jffng jffng added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Block] Read More Affects the Read More Block labels Nov 2, 2022
@jffng jffng requested a review from ajitbohra as a code owner November 2, 2022 14:56
@codesandbox
Copy link

codesandbox bot commented Nov 2, 2022

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@jffng jffng requested a review from joedolson November 2, 2022 14:56
@carolinan
Copy link
Contributor

carolinan commented Nov 2, 2022

Thank you for working on this Jeff.
When an aria-label is added to a link, the aria-label replaces any link text.
When I test the PR with VoiceOver, it reads: "Visited, link, Post ID: 158" even if a valid link text is added.
Edit: It also meant that the screen reader text didn't show up in the top corner of the screen.

Did you intend to use the Post ID only if there is no post title?

@jffng
Copy link
Contributor Author

jffng commented Nov 2, 2022

Ah I see, thank you for explaining, I'm quite new to working on accessibility issues.

Did you intend to use the Post ID only if there is no post title?

I used the post ID here because of the comment in the original issue:

The block should always include relevant details to clarify the link target using one of aria-label, aria-describedby with a reference pointing to the title by ID

Maybe I misunderstood the feedback, and it would make sense to return a better description (e.g. Read more about "My Post Title"), and use only the post ID if there is no post title. How does that sound?

@carolinan
Copy link
Contributor

It would solve part of the issue if the default visible text was changed from "Read more" to "Read more about post title".

The problem with that is that it would change the text for users who are using the old default and it may be unexpected for them.

Just brainstorming:

  • Make the updated text the new default visible text
  • Add a setting to visually hide the post title
  • Enable that setting for existing blocks, so that users who are using the current default, see no change (I don't know how to do this :) )
  • For scenarios where the text has been edited, add an aria-describedby with the post title.

If we are choosing between aria-label and screen reader text, I think that screen reader text may help more people since it is also visible, even if only when the link is focused?

@jffng
Copy link
Contributor Author

jffng commented Nov 3, 2022

If we are choosing between aria-label and screen reader text, I think that screen reader text may help more people since it is also visible, even if only when the link is focused?

👍 I will update the PR accordingly.

@jffng jffng force-pushed the add/read-more-accessible-output branch from 409da8d to 12c24f7 Compare November 3, 2022 16:24
@jffng jffng requested a review from carolinan November 3, 2022 18:48
@joedolson
Copy link
Contributor

The reference "pointing to the title by ID" refers to the mechanism of using aria-describedby. Simple example code would be like so:

<h2 id="post-58">Title</h2><a href="permalink" aria-describedby="post-58">Read more</a>

That creates a relationship between 'read more' and the post title so that the link is described by the title, and the reference is to the ID attribute of the post title.

Using screen reader text is, however, probably a better solution, as it is supported in a broader capacity and easier to make visible when needed.

@jffng
Copy link
Contributor Author

jffng commented Nov 3, 2022

Thanks for the clarification. Would the redundancy of having both aria-describedby and screen reader text be helpful, or is it sufficient to only provide the screen reader text with a sensible message e.g. Read more about "My Post Title"?

@joedolson
Copy link
Contributor

No, only provide one option. Having both, e.g.

<h2 id="post-58">Post Title</h2><a href="permalink" aria-describedby="post-58">Read more<span class="screen-reader-text"> about "Post Title"</span></a>

would result in reading "Read more about Post Title [pause] Post Title"; the redundancy would mostly just be annoyingly verbose.

@carolinan
Copy link
Contributor

carolinan commented Nov 4, 2022

VoiceOver reads this change as:

  1. Without custom text, with post title: "visited link, Read more read more about post title"
  2. With custom text, with post title "visited link, custom text read more about post title"
  3. Without post title: "visited link, Read more read more about"

(I do not hear a pause, but I am not a screen-reader user)
Nit:
Please use sprintf and a translators comment for the combination of the screen reader text and title

@jffng
Copy link
Contributor Author

jffng commented Nov 4, 2022

Thanks for the feedback and bearing with me!

I pushed a commit that attempts to make the screen reader text more compatible with all scenarios, using a colon instead of "Read more about" to avoid the redundancy — what do you think?

Copy link
Contributor

@joedolson joedolson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good! Some changes still need consideration.

$justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}";
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) );
$more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' );
return sprintf(
'<a %1s href="%2s" target="%3s">%4s</a>',
'<a %1s href="%2s" target="%3s">%4s<span class="screen-reader-text">%5s</span></a>',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a space between the visible link text and the hidden text, otherwise the words will be pasted together. e.g. <a %1s href="%2s" target="%3s">%4s<span class="screen-reader-text"> %5s</span></a>

See the space inside the screen-reader-text span.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make "grammatical" sense in cases where the user has customized the "read more" text, I went with the following format:

Read More: Post Title

See https://github.com/WordPress/gutenberg/pull/45490/files#diff-5fed9d866f33e17d5bf917f312bcae02af3c8bd244586ab161ed60889c960af6R25

Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Also good for internationalization.

/* translators: %s is either the post title or post ID to describe the link for screen readers. */
$screen_reader_text = sprintf(
__( ': %s' ),
$post_title !== '' ? $post_title : __( 'post ' ) . $post_ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case where the post has no title? The post ID does differentiate links, but not in any way that's useful to the user, so I'm wondering if there's a better fallback option.

Copy link
Contributor Author

@jffng jffng Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I'm not sure. We could use aria-describedby in this case, but again not sure if this is any more useful because it's linking the read more to a post that has no title.

Would it be better to state that there is no post title, e.g. Read More: (post with no title)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the scenario where an implementation uses primarily posts with no titles (ugly, but I've seen it), that would result in a series of identical links. Perhaps a combination, e.g. Read More: untitled post $post_ID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a combination, e.g. Read More: untitled post $post_ID

Done in 369691d

@jffng jffng force-pushed the add/read-more-accessible-output branch from 369691d to d98f6ad Compare November 8, 2022 19:28
@jffng
Copy link
Contributor Author

jffng commented Nov 9, 2022

@alexstine would you be able to give this a review?

Copy link
Contributor

@tellthemachines tellthemachines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good and it's working well in testing on VoiceOver/Safari. When post has a title, it's reading "Read more: post title". If there's no title, it reads "Read more: untitled post 234".

@jffng jffng merged commit 780def8 into trunk Nov 10, 2022
@jffng jffng deleted the add/read-more-accessible-output branch November 10, 2022 00:55
@github-actions github-actions bot added this to the Gutenberg 14.6 milestone Nov 10, 2022
@alexstine
Copy link
Contributor

@tellthemachines Thanks for testing/reviewing, I have been swamped with day job stuff lately.

@jffng Awesome improvement, thanks.

$screen_reader_text = sprintf(
/* translators: %s is either the post title or post ID to describe the link for screen readers. */
__( ': %s' ),
'' !== $post_title ? $post_title : __( 'untitled post ' ) . $post_ID
Copy link
Contributor

@youknowriad youknowriad Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We received this feedback related to this change https://core.trac.wordpress.org/ticket/57471#comment:27

Basically we should avoid concatenation when it comes to translated strings.

Let's make sure to follow-up on that and label the PR with the "backport to WP beta/RC" label to include on the next package update in core.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked here #47812

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Read More Affects the Read More Block [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants